#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define LED_ON 1
#define LED_OFF 0

int main(int argc, char const *argv[])
{
    int fd, ret;
    unsigned int cmd;

    if (argc != 2)
    {
        printf("Usage: <./app> <devname>]\r\n");
        return 0;
    }

    fd = open(argv[1], O_RDWR);
    if (fd < 0)
    {
        printf("open %s is fail\r\n", argv[1]);
        return -1;
    }

    while (1)
    {
        cmd = LED_ON;
        write(fd, &cmd, 1);
        printf("led is on\r\n");
        sleep(1);
        cmd = LED_OFF;
        write(fd, &cmd, 1);
        printf("led is off\r\n");
        sleep(1);
    }

    close(fd);

    return 0;
}
